package com.ctrip.demo.leetcode;

public class LeetCode2043 {

    public static void main(String[] args) {

    }

    class Bank {
        long[] val;

        public Bank(long[] balance) {
            this.val = balance;
        }

        boolean check(int account) {
            return 1 <= account && account <= val.length;
        }
        public boolean transfer(int account1, int account2, long money) {

            if (!check(account1) || !check(account2)) {
                return false;
            }
            if (val[account1 - 1] >= money) {
                val[account1 - 1] -= money;
                val[account2 - 1] += money;
                return true;
            }
            return false;
        }

        public boolean deposit(int account, long money) {
            if (!check(account)) {
                return false;
            }
            val[account - 1] += money;
            return true;
        }

        public boolean withdraw(int account, long money) {
            if (!check(account)) {
                return false;
            }
            if (val[account - 1] >= money) {
                val[account - 1] -= money;
                return true;
            }
            return false;
        }
    }
}
